﻿#ifndef DAMESSAGELOGSMODEL_H
#define DAMESSAGELOGSMODEL_H
#include "DAGlobals.h"
#include <QAbstractTableModel>

namespace DA
{
class DAMessageLogItem;
DA_IMPL_FORWARD_DECL(DAMessageLogsModel)
/**
 * @brief 用于显示全局消息的model
 */
class DAMessageLogsModel : public QAbstractTableModel
{
    Q_OBJECT
    DA_IMPL(DAMessageLogsModel)
public:
    DAMessageLogsModel(QObject* p = nullptr);
    ~DAMessageLogsModel();

    QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
    int columnCount(const QModelIndex& parent = QModelIndex()) const override;
    int rowCount(const QModelIndex& parent = QModelIndex()) const override;
    QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
    Qt::ItemFlags flags(const QModelIndex& index) const override;
    bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;

public:
    //是否显示时间列
    void setShowDateTime(bool on = true);
    //是否显示时间
    bool isShowDateTime() const;
    //设置不同消息类型的背景颜色
    void setTypeBackgroundColor(QtMsgType type, const QColor& clr);
private slots:
    //有消息插入触发的槽
    void onMessageAppended();
    void onMessageQueueSizeChanged(int newSize);

protected:
    virtual QVariant dataDisplay(DAMessageLogItem* item, const QModelIndex& index) const;
    virtual QVariant dataDecoration(DAMessageLogItem* item, const QModelIndex& index) const;
    virtual QVariant dataBackground(DAMessageLogItem* item, const QModelIndex& index) const;
    virtual QVariant dataToolTip(DAMessageLogItem* item, const QModelIndex& index) const;
};
}  // namespace DA
#endif  // DAMESSAGELOGSMODEL_H
